<template>
  <div>
    <!-- table -->
    <!-- 质量报告查询 - 明细 -->
    <BreakSpace label="质量信息" :containerStyle="{ marginBottom: '10px' }"/>
    <FormPanel ref="formPanel1" :list="formList" :cols="3" :formType="'add'" labelWidth="120" :isSubmitBtn="false"
               @formChange="formChangeHandle"/>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="故障码列表" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table1"
      :columns="columns"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :is-select-column="false"
      :isPagination = false
      height="auto"
    ></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="换下件配件列表" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table2"
      :columns="columns2"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns2 = columns2)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :is-select-column="false"
      :isPagination = false
      height="auto"
    > </FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <BreakSpace label="历史审核记录" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table3"
      :columns="columns3"
      :params="fetchParams"
      :datakey="'items'"
      :onColumnsChange="columns => (this.columns3 = columns3)"
      :onRowSelectChange="selectChange"
      selectionType="single"
      :is-select-column="false"
      :isPagination = false
      height="auto"
    ></FilterTable>
    <div style="margin-bottom: 1rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }">
      <multiuse-button type="primary" @click="closeDialog">关 闭</multiuse-button>
    </div>
    <div style="margin-bottom: 4rem;"></div>
  </div>
</template>
<script>
import { getPartType } from '@/api/dictionary/index';
import { quySP}  from '@/api/claim/dealer/ClaimApplication/index';
import { isFormEmpty } from '@/utils/index';
import {quyRpQaReport,editSave} from '@/api/claim/dealer/QualityInformationManagement_DLR/QualityInformationFeedback/index';
import { dictionary } from '@/utils/dictMixin';
export default {
  props: ['type', 'rowData'],
  mixins: [dictionary],
  components: {
  },
  data() {
    return {
      collapse: false,
      infoId: null,
      columns: this.creatHeader(),
      columns2: this.creatHeader2(),
      columns3: this.creatHeader3(),
      // topFilterInit: this.topFilterInitFun(),
      // fetchApi: getUser,
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList: this.createFormList(),
      saveData: null,
      weixiugongdan: false,
      zhusunjian:false,
      guzhangxianxiangdaima:false,
      application:false,
      peijianhuanxiajianlistaddflag:false,
      fault:false,
    };
  },
  created() {
    this.getList(this.rowData.reportId);
    this.chuqi();
  },
  methods: {
    async chuqi() {
      // console.log("进来了")
      // const res1 = await getPartType({type: 5561});
      // if (res1.resultCode == 200) {
      //   this.formList.find(x => x.fieldName == 'reportStatus').itemList = res1.data.map(y => ({
      //     text: y.codeCnDesc,
      //     value: y.codeId
      //   }));
      // }
      // const res3 = await getPartType( {type:5500});
      // if (res3.resultCode == 200) {
      //   this.formList.find(x => x.fieldName == 'isKeep').itemList = res3.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
      // }
    },
    async getList(id) {
      let res = await quyRpQaReport({ id: id });
      let data = res.data;
      //临时属性
      this.partId = data.partId; //主损件id
      this.supCode = data.supCode; //供应商Code
      this.modelId = data.modelId; //车型id
      this.modelCode = data.modelCode; //车型Code
      this.faultId = data.faultId; //故障现象主键
      this.isDeleted = data.isDeleted;
      this.applyAt = data.applyAt;
      this.cmsClaimId = data.cmsClaimId;
      this.claimStatus = data.claimStatus;
      // this.prodDate = data.prodDate;
      //为2个form赋值
      for (let i in data) {
        this.formList.map(y => {
          if (i == y.fieldName) {
            y.initialValue = data[i];
          }
        });

        this.formList.forEach(x => {
          x.initialValue = data[x.fieldName];
          if (x.fieldName == 'fileList') {
            x.initialValue = data.fileList.map((f) => ({ name: f.title, url: f.fileUrl }));
          }
        });
      }
      let fileIds = [];
      data.fileList.map(x =>{
        fileIds.push(x.fileId);
      });
      let idsss = '';
      fileIds.map(x => {
        idsss += x + ','
      });
      this.fileIds = idsss;

      //为table赋值

      if (200 == res.resultCode) {
        let data = res.data;
        if (isFormEmpty(data)) {
          data = {};
        }
        let records1 = data.logList;
        if (isFormEmpty(records1)) {
          records1 = [];
        }
        this.$refs.table3.$refs.pageTable.EXECUTE_INSERT(records1);
      }
      let records2 = data.partList;
      if (isFormEmpty(records2)) {
        records2 = [];
      }
      let partIds = [];
      this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(records2);
      this.$refs.table2.$refs.pageTable.list.map(x => {
        partIds.push(x.partId);
      });
      let ids = '';
      partIds.map(x => {
        ids += x + ','
      });
      this.partIds = ids;
      let records3 = data.faultList;
      if (isFormEmpty(records3)) {
        records3 = [];
      }
      let faultIds = [];
      this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(records3);
      this.$refs.table1.$refs.pageTable.list.map(x => {
        faultIds.push(x.faultId);
        this.faultIds = faultIds;
      });
      let idss = '';
      faultIds.map(x => {
        idss += x + ','
      });
      this.faultIds = idss;
      console.info(res);
    },
    faultAdd() {
      this.fault = true;
    },
    faultSave(val) {
      this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(val);
      this.fault = false;
    },
    faultClose() {
      this.fault = false;
    },


    //配件换下件列表
    peijianhuanxiajianadd() {
      this.peijianhuanxiajianlistaddflag = true;
    },
    //配件换下件
    peijianhuanxiajianClose() {
      this.peijianhuanxiajianlistaddflag = false;
    },
    peijianhuanxiajianSave(val) {
      let falg = true ;
      this.$refs.table2.$refs.pageTable.list.map(x => {
        for(let i in val){
          let node = val[i];
          if(node.partCode == x.partCode){
            falg = false;
            this.$notify.error({ title: '提示信息', message: '配件选择重复' });
          }
        }
      });
      if(falg){
        this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(val);
      }
      this.peijianhuanxiajianlistaddflag = false;
    },
    async getAuthListByauthNo(id) {
      let res = await quySP({ id: id });
      let data = res.data;
      let records2 = data.partList;
      if (isFormEmpty(records2)) {
        records2 = [];
      }
      this.$refs.table2.$refs.pageTable.EXECUTE_DELETE(this.$refs.table2.$refs.pageTable.list);
      this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(records2);
    },
    delsFunXj(data) {
      this.$refs.table1.$refs.pageTable.EXECUTE_DELETE([data]);
    },
    selectApplicationCode(){
      this.application = true;
    },
    selectpartCode() {
      this.zhusunjian = true;
    },
    selectRono() {
      this.weixiugongdan = true;
    },
    selectfaultCode() {
      this.guzhangxianxiangdaima = true;
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', {visible: false, data: this.selectedRows, type: 'close'});
    },
    //维修工单
    weixiugongdanClose() {
      this.weixiugongdan = false;
    },
    guzhangxianxiangdaimanClose() {
      this.guzhangxianxiangdaima = false;
    },
    applicationClose(){
      this.application = false;
    },
    applicationSave(obj){
      this.formList.find(x => x.fieldName == 'cmsClaimNo').initialValue = obj[0].claimNo;
      this.cmsClaimId = obj[0].claimId;
      this.getAuthListByauthNo(this.cmsClaimId);
      this.application = false;
    },
    guzhangxianxiangdaimaSave(obj) {
      this.formList.find(x => x.fieldName == 'sysCode1').initialValue = obj[0].sysCode1;
      this.formList.find(x => x.fieldName == 'sysName1').initialValue = obj[0].sysName1;
      this.formList.find(x => x.fieldName == 'sysCode2').initialValue = obj[0].sysCode2;
      this.formList.find(x => x.fieldName == 'sysName2').initialValue = obj[0].sysName2;
      this.formList.find(x => x.fieldName == 'sysCode3').initialValue = obj[0].sysCode3;
      this.formList.find(x => x.fieldName == 'sysName3').initialValue = obj[0].sysName3;
      this.formList.find(x => x.fieldName == 'sysCode4').initialValue = obj[0].sysCode4;
      this.formList.find(x => x.fieldName == 'sysName4').initialValue = obj[0].sysName4;
      this.formList.find(x => x.fieldName == 'faultCode').initialValue = obj[0].faultCode;
      this.formList.find(x => x.fieldName == 'faultName').initialValue = obj[0].faultName;
      this.faultId = obj[0].faultId;
      this.guzhangxianxiangdaima = false;

    },
    //主损件
    zhusunjianClose() {
      this.zhusunjian = false;
    },
    zhusunjianSave(obj) {
      this.formList.find(x => x.fieldName == 'partCode').initialValue = obj[0].partCode;
      this.formList.find(x => x.fieldName == 'partName').initialValue = obj[0].partName;
      this.partId = obj[0].partId;
      this.zhusunjian = false;
    },
    weixiugongdanSave(obj) {
      // this.formList.find(x => x.fieldName == 'claimNo').initialValue = obj[0].claimNo;
      this.formList.find(x => x.fieldName == 'roNo').initialValue = obj[0].roNo;
      this.formList.find(x => x.fieldName == 'vin').initialValue = obj[0].vin;
      this.formList.find(x => x.fieldName == 'modelName').initialValue = obj[0].modelName;
      this.formList.find(x => x.fieldName == 'saleDate').initialValue = obj[0].saleDate;
      this.formList.find(x => x.fieldName == 'serviceBeginDate').initialValue = obj[0].serviceBeginDate;
      this.formList.find(x => x.fieldName == 'serviceEndDate').initialValue = obj[0].serviceEndDate;
      this.formList.find(x => x.fieldName == 'prodDate').initialValue = obj[0].prodDate;
      this.formList.find(x => x.fieldName == 'driveMile').initialValue = obj[0].driveMile;
      this.modelCode = obj[0].modelCode;
      this.modelId = obj[0].modelId;
      this.weixiugongdan = false;
    },
    //质量信息
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '质量报告单号',
          fieldName: 'reportNo',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '维修工单号',
          fieldName: 'roNo',
          placeholder: '请输入标题名称...',
          readonly: true,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '质量报告状态',
          fieldName: 'reportStatus',
          placeholder: '请输入标题名称...',
          disabled: true, // 只读
          itemList: this.createDictList('5561'),
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'DATE',
          label: '生产日期',
          fieldName: 'prodDate',
          valueFormat: 'yyyy-MM-dd',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'DATE',
          label: '销售日期',
          fieldName: 'saleDate',
          valueFormat: 'yyyy-MM-dd',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '维修开始时间',
          fieldName: 'serviceBeginDate',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '维修结束时间',
          fieldName: 'serviceEndDate',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'driveMile',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '车型名称',
          fieldName: 'modelName',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '制单人',
          fieldName: 'reporter',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '联系方式',
          fieldName: 'phone',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '主损件',
          fieldName: 'partCode',
          placeholder: '请输入数量...',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '主损件名称',
          fieldName: 'partName',
          readonly: true,// 只读
          disabled: true, // 置会
        },
        {
          type: 'INPUT',
          label: '索赔单号',
          fieldName: 'cmsClaimNo',
          readonly: true,// 只读
          disabled: true
        },
        {
          type: 'INPUT',
          label: '故障现象代码',
          fieldName: 'faultCode',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true
        },
        {
          type: 'INPUT',
          label: '故障现象描述',
          fieldName: 'faultName',
          readonly: true,// 只读
          disabled: true, // 置会
        },
        {
          type: 'INPUT',
          label: '一级代码',
          fieldName: 'sysCode1',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '一级名称',
          fieldName: 'sysName1',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '二级代码',
          fieldName: 'sysCode2',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '二级名称',
          fieldName: 'sysName2',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '三级代码',
          fieldName: 'sysCode3',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '三级名称',
          fieldName: 'sysName3',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '故障代码',
          fieldName: 'sysCode4',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'INPUT',
          label: '故障名称',
          fieldName: 'sysName4',
          placeholder: '请输入数量...',
          readonly: true,// 只读
          disabled: true // 置会
        },
        {
          type: 'SELECT',
          label: '是否留车',
          fieldName: 'isKeep',
          placeholder: '请输入...',
          itemList: this.createDictList('5500'),
          disabled: true,
          change: val => {
            if (val == 55001001) {
              this.formList.map(y => {
                if (y.fieldName == 'keepCar') {
                  y.disabled = false;
                  y.rules[0].required = true;
                }
              })
            } else {
              this.formList.map(y => {
                if (y.fieldName == 'keepCar') {
                  y.disabled = true;
                  y.initialValue = '';
                  y.rules[0].required = false;
                }
              })
            }
          }
        },
        {
          type: 'INPUT',
          label: '留车单号',
          fieldName: 'keepCar',
          placeholder: '请输入数量...',
          disabled: true, // 置会
        },
        {
          type: 'TEXT_AREA',
          label: '故障描述',
          fieldName: 'cmsClaimInfo',
          selfCols: 3,// 元素占据几行
          rows: 3,
          disabled: true,
        },
        {
          type: 'TEXT_AREA',
          label: '维修经过',
          fieldName: 'cmsClaimProcess',
          selfCols: 3,// 元素占据几行
          rows: 3,
          disabled: true,
        },
        {
          type: 'TEXT_AREA',
          label: '维修结果',
          fieldName: 'cmsClaimResult',
          selfCols: 3,// 元素占据几行
          rows: 3,
          disabled: true,
        },
        {
          type: 'TEXT_AREA',
          label: '建议意见',
          fieldName: 'suggestion',
          selfCols: 3,// 元素占据几行
          rows: 3,
          disabled: true,
        },
        {
          type: 'TEXT_AREA',
          label: '使用环境',
          fieldName: 'useEvn',
          selfCols: 3,// 元素占据几行
          rows: 3,
          disabled: true
        },
        {
          type: 'UPLOAD_FILE',
          label: '上传文件',
          fieldName: 'fileList',
          placeholder: '上传文件...',
          disabled: true,
          initialValue: [],
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 2,
            // tipText: '只能上传pdf格式'
          }
        }
      ];
    },
    //故障码列表
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '故障码', dataIndex: 'faultCode', sorter: true},
        {title: '故障码描述', dataIndex: 'faultName', sorter: true},
      ];
    },
    //配件列表
    creatHeader2() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '配件代码', dataIndex: 'partCode', sorter: true },
        { title: '配件名称', dataIndex: 'partName', sorter: true },
        { title: '单位', dataIndex: 'partUnit', sorter: true },
        { title: '数量', dataIndex: 'partCount', sorter: true }
      ];
    },
    //历史审核记录
    creatHeader3() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '操作人', dataIndex: 'checkBy', sorter: true},
        {title: '操作时间', dataIndex: 'checkAt', sorter: true},
        {title: '操作类型', dataIndex: 'statusStr', sorter: true},
        {title: '操作备注', dataIndex: 'checkRemarks', sorter: true}
      ];
    },


  }
};
</script>

<style lang="less" scoped></style>
